﻿@using Website.CRUDServices
@{
    this.ViewBag.Title = "Nyhedsinformation";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var Funds = this.ViewData["Funds"] as List<Fund>;
    var Projects = this.ViewData["Projects"] as List<Project>;
    var Types = this.ViewData["Types"] as List<NewsInformationType>;
    var errorMsg = new HtmlString(string.Empty);
    var filesInfo = this.ViewData["FilesInfo"] as List<Website.CRUDServices.File> ?? new List<Website.CRUDServices.File>();
    if (this.ViewData["ErrorMessage"] != null)
    {
        errorMsg = this.ViewData["ErrorMessage"] as HtmlString;
    }

    var News = this.Model as NewsInformation;
}

@Html.Partial("~/Views/_Shared/LogView.cshtml", News.ID)

<script type="text/javascript">
    //toggle script
    function toggle(id) {
        if (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == "") {
            document.getElementById(id).style.display = 'block';
        }
    }

    function reverseToggle(id) {
        if (document.getElementById(id).style.display == 'block') {
            document.getElementById(id).style.display = 'none';
        }
    }

    //show/his script

    function checkType(id) {
        var selectTypeObj = document.getElementById('Type');

        if (selectTypeObj.selectedIndex == -1) {
            return;
        }

        var selectChosenType = selectTypeObj.options[selectTypeObj.selectedIndex].text;

        if (selectChosenType == 'Nyhedsbrev') {
            toggle(id);
        } else {
            if (selectChosenType == 'Formidlings information') {
                toggle(id);
            } else {
                reverseToggle(id);
            }
        }
    }
</script>
@if (News.IsInformationAboutFunds || News.IsInformationAboutProgress || News.IsInformationAboutResults)
{
    <script>
        $(function () {
            toggle('additionals');
        });
    </script>
}
@if (News.IsInformationAboutFunds)
{
    <script>
        $(function () {
            toggle('showFunds');
        });
    </script>
}



@*// *******************Nyhedsinformation**************************@


@*// name*@
<fieldset class="chosenFields">
    <legend>Navn på nyhedsinformation</legend>
    @News.Name
</fieldset>

@*// date*@
<fieldset class="chosenFields">
    <legend>Dato</legend>
    @if (News.TimeOfActivity.HasValue)
    {
        @News.TimeOfActivity.Value.ToShortDateString()}
</fieldset>

@*// ownerProjects chooser*@
<fieldset class="chosenFields">
    <legend>Alle projekter tilknyttet</legend>

    @foreach (Project proj in Projects.Where(x => (News.OwnerProjects ?? new Guid[0]).Contains(x.ID)))
    {
        @proj.Name <br />
    }
</fieldset>

@*// types chooser*@
<fieldset class="chosenFields">
    <legend>Nyhedstype</legend>
    @foreach (NewsInformationType typ in Types)
    {
        if (News.Type == typ.ID)
        {
        @typ.Name <br />
        }
    }
</fieldset>


@*// explanation*@
<fieldset class="chosenFields">
    <legend>Yderligere beskrivelse</legend>@News.Comments
</fieldset>

<!--filechooser-->
<fieldset class="chosenFields">
    <legend>Eksisterende filer</legend>
    <script type="text/javascript">
        function openFile(id) {
            var url = "@Url.Action("Open", "File", new { ID = ".id." })";
            window.open(url.replace(".id.", id), "blank_" + id);
        }
    </script>
    <table class="fileTable" id="FileTable">

        @{
            var fileIDs = News.Files;

            foreach (var file in filesInfo.Where(x => fileIDs.Contains(x.ID)))
            {
            <tr id="@Html.Raw("tr_" + file.ID)">
                <td>@file.Name</td>
                <td>
                    <input type="button" value="Se fil" onclick="@Html.Raw("javascript:openFile('" + file.ID + "');")" />
                </td>
            </tr>
            }
        }
    </table>
</fieldset>

<!--archive location-->
<fieldset class="chosenFields">
    <legend>Fysisk arkiverings placering</legend>
    @News.ArchiveLocation"
</fieldset>

<div id="additionals" class="open_hidden">
    <br />
    <fieldset class="chosenFields">
        <legend>Information om:</legend>
        <br />

        @if (News.IsInformationAboutFunds)
        {
            <label>
                <input type="checkbox" name="informationType" value="funds" onchange=" toggle('showFunds') " checked />Fonde/puljer</label>
        }
        else
        {
            <label>
                <input type="checkbox" name="informationType" value="funds" onchange=" toggle('showFunds') " />Fonde/puljer</label>
        }
        @if (News.IsInformationAboutProgress)
        {
            <label>
                <input type="checkbox" name="informationType" value="progress" checked />Fremdrift</label>
        }
        else
        {
            <label>
                <input type="checkbox" name="informationType" value="progress" />Fremdrift</label>
        }
        @if (News.IsInformationAboutResults)
        {
            <label>
                <input type="checkbox" name="informationType" value="results" checked />Resultater</label>
        }
        else
        {
            <label>
                <input type="checkbox" name="informationType" value="results" />Resultater</label>
        }


        <div id="showFunds" class="open_hidden">
            <!--Funds-->
            <fieldset class="chosenFields">
                <legend>Vælg fonde/puljer</legend>

                @foreach (Fund fun in Funds.Where(x => (News.Funds ?? new Guid[0]).Contains(x.ID)))
                {
                    @fun.Name <br />
                }
            </fieldset>
        </div>
    </fieldset>
</div>
